package com.example.calccalories;

import org.w3c.dom.Text;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity{
	
	EditText usuario ;
	EditText contrasenia ;
	TextView alerta;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		usuario = (EditText)this.findViewById(R.id.EditTextUsername);
		contrasenia = (EditText)this.findViewById(R.id.EditTextPassword);
		alerta = (TextView)this.findViewById(R.id.textView_Error);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login, menu);
		return true;
	}
	
	
	public void  registrate(View v)
	{
		Intent i = new Intent(this, SignUpActivity.class);
		startActivity(i);	
	}
	
	public void  signup(View v)
	{
		String Usuario = usuario.getText().toString();
		String Contrasenia = contrasenia.getText().toString();
		
		if (Usuario.equals("")||Contrasenia.equals(""))
			alerta.setText("Correo y Contrasera Obligatorios");
		else
		{
			DbAdapter cuenta = new DbAdapter(this);	
			cuenta.open();
			boolean band = cuenta.IsUser(Usuario, Integer.parseInt(Contrasenia));
			cuenta.close();
			
			if (band)
			{
			Intent i = new Intent(this, MainActivity.class);
			startActivity(i);
			}else alerta.setText("Correo y Contrasera Incorrectos");
		}
	}	
	
}
